package ifi.sma.group5.agents;

import ifi.sma.group5.db.AssistantModel;
import ifi.sma.group5.gui.AssistantGui;
import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.CyclicBehaviour;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;

public class Assistant extends Agent{
	
	/*
	 * 
	 */
	private AssistantGui gui;
	private AssistantModel assistantModel;
	private String message;
	
	protected void setup() {
		super.setup();
		DFAgentDescription dfd = new DFAgentDescription();
		dfd.setName(getAID());
		ServiceDescription sd = new ServiceDescription();
		sd.setType("etudiant_demander");
		sd.setName("JADE-book-trading");
		dfd.addServices(sd);
		
		gui = new AssistantGui();
		
		
		addBehaviour(new EtudiantConnect());
		
		try{
			DFService.register(this, dfd);
		}catch(FIPAException fe) {
			fe.printStackTrace();
		}
	}
	
	private class EtudiantConnect extends CyclicBehaviour {
		@Override
		public void action() {
			// TODO Auto-generated method stub
			ACLMessage msg = myAgent.receive();
			MessageTemplate mt = 	MessageTemplate.MatchPerformative(ACLMessage.CFP);
			msg = myAgent.receive(mt);
			if(msg != null) {
					AID sender = msg.getSender();
					System.out.println("sender"+sender.toString());
					String content = msg.getContent();
					System.out.println("content"+content);
					System.out.println("j'ai bien recu");
			}
		}		
	}
}
